class DeployHistoryController < ApplicationController
  def index
    if current_user.can_list_all_app_his?
      @deployHistories = DeployHistory.all.where("status = 1 and start_time >= current_date-7").order(id: :desc)
    else
      @deployHistories = DeployHistory.all.where("status = 1 and start_time >= current_date-7").order(id: :desc).where("username=?",current_user.username)
  end

  def quick_index
    @deployHistoriesHash = {0 => [], 1 => [], 9 => []}
    deployHistories = DeployHistory.select(DeployHistory.attribute_names - ['log'])
                          .where("start_time > current_date").order(id: :asc)
    deployHistories.each{ |history|
      status = history.status
      history.log = ""
      @deployHistoriesHash[status] << history

    }
    render json: @deployHistoriesHash
  end

  def show_log
    deployHistory = DeployHistory.find(params[:id])
    log = deployHistory.log
    #替换\n成br，浏览器显示时会换行，方便浏览
    log = log.gsub("\n", '<br>') if log
    render :text => log
  end
  end
end
